//
//  CZMainViewController.swift
//  WHWeiBo87
//
//  Created by Mac on 16/7/13.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class CZMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
       //越早执行越好，一般会放到appDelegate里面
//        UITabBar.appearance().tintColor = UIColor.orangeColor()
        
        //添加子视图控制器的两种方式
        
        //        ViewController = [xx.]
        //
        //        addchildViewController(xx)
        
        
        //指定tabbar
        let czTabbar = CZTabBar()
        //使用Kvc 给只读属性设置值
        setValue(czTabbar, forKey: "tabBar")
        
        
        addChildViewController(CZHomeTableViewController(),title: "首页",imageName: "tabbar_home")
        
        addChildViewController(CZMessageTableViewController(),title: "消息",imageName: "tabbar_message_center")
        addChildViewController(CZDiscoverTableViewController(),title: "发现",imageName: "tabbar_discover")
        
        addChildViewController(CZProfileTableViewController(),title: "我的",imageName: "tabbar_profile")
        
    }
    
    //重载  addChildViewController
    func addChildViewController(childController: UIViewController,title:
        String,imageName : String) {
            
//            childController.tabBarItem.title = title
            childController.title = title
            
            childController.tabBarItem.image = UIImage(named: imageName)
            
            childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")
            
            
            //指定渲染模式
            
        childController.tabBarItem.selectedImage = UIImage(named: imageName +
             "_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
            
            //设置tabbar字体颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()],forState: .Selected)
            
            // 设置字体
//    childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIFont.systemFontOfSize(14)], forState: .Normal)
//            
            //添加子视图控制器
            let nav = UINavigationController(rootViewController: childController)
            
            addChildViewController(nav)
            
    }
  
}
